﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Transactions {
    import Engine.Managers.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Modules.stats.experiments.*;

    public class TRefreshUser extends TInitUser {

        private static var m_numRefreshes:int = 0;
        private static var MAX_REFRESHES:int = 1;

        private var m_dialog:GenericDialog = null;
        private var m_causedByError:Boolean = false;

        public function TRefreshUser(_arg1:String, _arg2:Boolean=false){
            MAX_REFRESHES = RuntimeVariableManager.getInt("REFRESH_USER_LIMIT", 1);
            this.m_causedByError = _arg2;
            UI.flushDialogs();
            this.m_dialog = UI.displayMessage(ZLoc.t("Main", "ResolvingIssues"), GenericDialogView.TYPE_NOBUTTONS, null, "", true);
            Sounds.stopAnyLoopingSounds();
            Global.setVisiting(null);
            Global.ui.updateVisitMode(false);
            TransactionManager.initialize();
            ConnectionStatus.stopTimeout();
            super(_arg1);
        }
        public static function canCall(_arg1:Boolean):Boolean{
            var _local2:int = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_REFRESH_USER);
            var _local3 = (_local2 == ExperimentDefinitions.REFRESH_USER);
            if (_arg1){
                _local3 = ((_local3) && ((m_numRefreshes < MAX_REFRESHES)));
            };
            return (_local3);
        }

        override protected function onComplete(_arg1:Object):void{
            if (_arg1 != null){
                loadWorld(_arg1);
                if (this.m_causedByError){
                    m_numRefreshes++;
                };
                StatsManager.count("refresh", "user_state");
            } else {
                GameUtil.reloadApp(true, "fail_refresh_user");
            };
            if (this.m_dialog){
                this.m_dialog.close();
            };
        }
        override protected function onFault(_arg1:int, _arg2:String):void{
            GameUtil.reloadApp(true, "amf_fault_refresh_user");
        }

    }
}//package Transactions 
